package start.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baidu.ueditor.ActionEnter;
@WebServlet("/ueditor/controller")
public class UEditorController extends HttpServlet {
	
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String root = request.getServletContext().getRealPath("/");
		
		String action = request.getParameter("action");
		
		
		String str = new ActionEnter( request, root).exec();
		if( action!=null && (action.equals("listfile") || action.equals("listimage") ) ){
		   root = root.replace("\\", "/");
		   str = str.replaceAll(root, "/");
		}	
		PrintWriter out = response.getWriter();
		
		out.write(str);
		out.flush();
		out.close();
		
	}
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
		this.doGet(request, response);
	}
}
